package org.example;

import java.util.Random;
import java.util.Scanner;
//双色球中奖规则
public class testt2 {
    public static void main(String[] args) {
        int []arr=creatNumber();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        System.out.println("==============");
        int []arr1=useterNumber();
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]+" ");
        }
        int redcount=0;
        int bluecount=0;
        for (int i = 0; i < arr1.length-1; i++) {
            int redNumber=arr[i];
            for (int j = 0; j < arr.length-1; j++) {
                if(redNumber==arr[j]){
                    redcount++;
                    break;
                }
            }
        }
        int blueNumber=arr1[arr.length-1];
        if(blueNumber==arr[arr.length-1]){
            bluecount++;
        }
        System.out.println("Redcount:"+redcount);
        System.out.println("Bluecount:"+bluecount);
        if(redcount==6&&bluecount==1){
            System.out.println("恭喜你中了一等奖");
        }else if(redcount==6&&bluecount==0){
            System.out.println("恭喜你中了二等奖");
        }else if(redcount==5&&bluecount==1){
            System.out.println("恭喜你中了三等奖");
        }else if((redcount==5&&bluecount==0)||(redcount==4&&bluecount==1)){
            System.out.println("恭喜你中了四等奖");
        }else if((redcount==4&&bluecount==0)||(redcount==3&&bluecount==1)){
            System.out.println("恭喜你中了五等奖");
        }else if((redcount==2&&bluecount==1)||(redcount==1&&bluecount==1)||(redcount==0&&bluecount==1)){
            System.out.println("恭喜你中了六等奖");
        }else{
            System.out.println("很遗憾，你没有中奖");
        }






    }
    public static int[] creatNumber(){
        int []arr=new int[7];
        Random rand=new Random();
        for (int i = 0; i < 6; ) {
            int rednum = rand.nextInt(33) + 1;
            boolean flag = isRepeat(arr, rednum);
            if (!flag) {
                arr[i] = rednum;
                i++;
            }
        }
            int bluenum=rand.nextInt(16)+1;
            arr[arr.length-1]=bluenum;
            return arr;
    }
    public static boolean isRepeat(int []arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==num){
                return true;
            }
        }
        return false;
    }
    public static int[] useterNumber() {
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第" + (i + 1) + "个红球：");
            int redNumber = sc.nextInt();
            if (redNumber >= 1 && redNumber <= 33) {
                boolean flag = isRepeat(arr, redNumber);
                if (!flag) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("你输入的号码重复了，请重新输入：");
                }
            } else {
                System.out.println("已超出范围，请重新输入：");
            }
        }
        while (true) {
            System.out.println("请输入蓝球：");
            int blueNumber=sc.nextInt();
            if(blueNumber>=1&&blueNumber<=16){
                arr[arr.length-1]=blueNumber;
                break;
            }else{
                System.out.println("已超出范围，请重新输入：");
            }
        }
        return arr;
    }





}
